package fun.anin.aninhongbao.receive;

import com.rabbitmq.client.Channel;
import fun.anin.aninhongbao.dto.WalletDTO;
import fun.anin.aninhongbao.service.WalletService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.IOException;

/***
 * 钱包队列的接收方
 * @author anin
 * @date: 2020/4/2 15:42
 * @version : V1.0
 */
@Slf4j
@Component
public class WalletReceive {

    @Autowired
    private WalletService walletService;

    @RabbitHandler
    @RabbitListener(queues = "redpacket.arrival")
    public void arrival(Message message, Channel channel, WalletDTO walletDTO) throws IOException {
        channel.basicAck(message.getMessageProperties().getDeliveryTag(),true);
        walletService.updateMoney(walletDTO);
    }
}
